<?php
namespace App\Services\System\Log;

use App\Services\Service;
use App\Services\Traits\DatabaseMysql;
use App\Models\Admin\Auth\UserLoginLog;

class LoginService extends Service
{
    use DatabaseMysql;

    /**
     * 获取数据列表
     *
     * @param \Illuminate\Http\Request $request            
     * @return \Illuminate\Database\Eloquent\Collection[]|int[]
     */
    public function getList($request)
    {
        $query = UserLoginLog::query();
        
        // 搜索
        if (ctype_digit($request->input('keyword'))) {
            // 操作人【ID】
            $this->makeWhereParam($request, 'keyword', $query, 'user_id');
        }
        // 默认值
        $this->makeWhereParam($request, 'default', $query);
        
        // 数据条数
        $total = (clone $query)->count();
        // 排序分页
        $this->makeOrderParam($request, $query)->makePaginationParam($request, $query);
        // 查询数据
        $collection = $query->with('user:id,name,email')->get();
        
        return [
            $collection,
            $total
        ];
    }
}
